<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
    <link rel="stylesheet" href="../javascripts/lib/jqm/jquery.mobile-1.4.3.min.css"/>
    <link rel="stylesheet" href="../stylesheets/main.css"/>
    <script src="../javascripts/lib/jq/jquery-2.1.1.min.js"></script>
    <script src="../javascripts/lib/jqm/jquery.mobile-1.4.3.min.js"></script>
    <script type="text/javascript">
        $(document).on("pageshow","#pagetwo",function(){
            var reletCount = $('#reletCount').val();
            var reletCount1 = $('#reletCount1').val();
            var msg = '您好，以下内容付费后方可查看，查看全部记录支付金额为<span id="rc" style="color: #FF0000;">'+reletCount+'</span>元，即<span id="rcCount" style="color: #FF0000;">'+reletCount1+'</span>次咨询次数';
            $('#payState').html(msg);
           /* $('#rc').html(reletCount);
            $('#rcCount').html(reletCount1);*/
        });

    </script>
    <title><%=title%></title>
</head>
<body>

<div data-role="page" id="pubChatDetailPage">
    <div data-role="header">
        <a class="ui-btn ui-icon-back ui-btn-icon-left" id="wcback">返回</a>
        <h1>热门话题</h1>
    </div>
    <div class="ui-content" role="main">

        <script type="text/javascript">

            function refreshChat(sid){
                $.get('/view/pubChatDetail?sid='+sid+'&uuid='+$('#uuid').val()+'&random='+Math.random(),function(result){
                    var data = '';
                    var messageList = result[0];
                    if(result[2]!='all'){//判断是不是全部显示
                        $('#reletCount').val(result[2]);
                        $('#reletCount1').val(result[3]);
                        //alert(messageList[0].wcsessionid);
                        $('#tip2').hide();
                        $('#tip1').show();
                        $('#chatSid').val(messageList[0].wcsessionid);
                        $('#moreChat').show();
                    }else{
                        $('#moreChat').hide();
                    }
                    for(var i=0;i<messageList.length;i++){
                        if(messageList[i].send_openid==result[1]){
                            data+='<div style="white-space:pre-wrap; margin: 3px;"><span style="color: #32CD32;font-weight: 700;">问：&nbsp;</span></div>'+
                            '<div style="white-space:pre-wrap;" >&emsp;&emsp;'+messageList[i].sendcontent+'</div>'
                        }else{
                            data+='<div style="white-space:pre-wrap; margin: 3px;"><span style="color: #4169E1;font-weight: 700;">答：&nbsp;</span></div>'+
                            '<div style="white-space:pre-wrap;" >&emsp;&emsp;'+messageList[i].sendcontent+'</div>'
                        }
                    }

                    data = '<li><div>'+data+'</div></li>';
                    $('#chatlist').html( data );
                    $('#chatlist').listview("refresh");
                    $('#chatlist').trigger("updatelayout");
                    //alert('ssssssssssssss');

                });
            }
            function goPay(){
                /*alert($('#chatSid').val());*/
                $.post('/wcpay/chatPay',{sid:$('#chatSid').val(), uuid:$('#uuid').val()},function(data){
                    if(data=="ok"){
                        $('#payState').html('支付成功！您现在可以查看所有记录！');
                        $('#tip1').hide();
                        $('#tip2').show();
                        refreshChat($('#chatSid').val());//支付成功后刷新聊天信息
                    }else{
                        $('#payState').html('支付失败！请到“用户菜单-购买服务”续费。');
                    }
                });
            };

            $(document).ready(function() {

                refreshChat($('#sid').val());
            });

            $("#wcback").click(function(){
                WeixinJSBridge.call('closeWindow');//微信内置浏览器关闭当前页面
            });
        </script>


        <ul id="chatlist" data-role="listview" data-inset="true" >

        </ul>
        <div id="moreChat" style="margin-top: 20px;">
            <a  data-role="button" data-icon="refresh"  data-iconpos="left"  href="#pagetwo" data-rel="dialog" data-transition="slidedown">
                显示更多
            </a>

            <input id="reletCount1" type="hidden" value=""/>
            <input id="reletCount" type="hidden" value=""/>
            <input id="chatSid" type="hidden" value=""/>
            <input id="uuid" type="hidden" value="<%=uuid%>">
            <input id="sid" type="hidden" value="<%=sid%>">
        </div>

    </div>
</div>

<div data-role="page" id="pagetwo" data-close-btn="right" data-overlay-theme="d">
    <div data-role="header">
        <h1>提示</h1>
    </div>

    <div data-role="content">
        <p><h4></h4></p>
        <h1>扣费提醒</h1>
        <p><span id="payState">您好，以下内容付费后方可查看，查看全部记录支付金额为<span id="rc" style="color: #FF0000;"></span>元，即<span id="rcCount" style="color: #FF0000;"></span>次咨询次数</span></p>
        <div id="tip1">
            <a href="#searchpage" data-rel="back" class="ui-btn ui-shadow ui-corner-all ui-btn-a">了解了</a>
            <a id="goPay" href="javascript:void(0)" onclick="goPay()" class="ui-btn ui-shadow ui-corner-all ui-btn-b">去支付</a>
        </div>
        <div id="tip2" style="display: none;">
            <a href="#searchpage" data-rel="back" class="ui-btn ui-shadow ui-corner-all ui-btn-a">返回</a>
        </div>

    </div>

</div>


</body>
</html>